package com.hao.tool.web.component.runner;

import com.google.common.base.Joiner;
import com.hao.tool.common.component.AppStartTips;
import com.hao.tool.web.component.SpringContextHolder;
import com.hao.tool.web.component.properties.PropertiesInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

/**
 * 项目启动提示
 *
 * @author sawyerlsy
 * @date 2019-08-06
 * @since
 */
@Component
@Order(value = 10)
@Slf4j
public class AppStartTipsRunner implements CommandLineRunner {

    @Value("${spring.application.name}")
    private String applicationName;
    @Value("${server.port}")
    private String serverPort;
    @Value("${server.servlet.context-path}")
    private String contextPath;


    @Autowired
    private PropertiesInfo propertiesInfo;

    @Override
    public void run(String... args) {

        //打印当前环境信息
        Environment environment = SpringContextHolder.getBean(Environment.class);
        final String activeProfiles = Joiner.on(",").join(environment.getActiveProfiles());
        log.info("{} has been started! environment is {}", applicationName, activeProfiles);


        AppStartTips.startTip(log, applicationName);

        System.out.println();
        System.out.println(">>>>>>>>>>>>>>>项目 " + applicationName + ":" + serverPort + contextPath + " 启动成功<<<<<<<<<<<<<");
        System.out.println(">>>>>>>>>>>>>>> " + "http://127.0.0.1" + ":" + serverPort + contextPath + " <<<<<<<<<<<<<");


    }
}
